package zt3;

import java.util.Scanner;

public class Main {
	static int[] arr;
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		arr=new int[6];
		for(int i=0;i<6;i++) {
			String temp = sc.next();
			if(temp.equals("Q")) {
				arr[i]=11;
			}else if (temp.equals("K")) {
				arr[i]=12;
			}else if (temp.equals("A")) {
				arr[i]=1;
			}else {				
				arr[i]=(int)(temp.charAt(0)-'0');
			}
			
		}
		int fla=0;
		for(int i=0;i<4;i++) {			
			if (fla==1) {
				break;
			}
			if (i==0) {
				if(dfs(2, arr[0]+arr[1])) {
					fla=1;
				}
			}else if (i==1) {				
				if(dfs(2, arr[0]-arr[1])) {
					fla=1;
				}
			}else if (i==2) {
				if(dfs(2, arr[0]*arr[1])){
					fla=1;
				}
			}else {
				if(dfs(2,arr[0]/arr[1])) {
					fla=1;
				}
			}
		}
		if (fla==1) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
	static boolean dfs(int chen,int num) {
		if (chen==6) {
		
			if (num==42) {
				return true;
			}
			return false;
		}
		int fla=0;
		for(int i=0;i<4;i++) {
			if (fla==1) {
				break;
			}
			if (i==0) {
				fla=dfs(chen+1,num+arr[chen])?1:0;
			}else if (i==1) {				
				fla=dfs(chen+1,num-arr[chen])?1:0;
			}else if (i==2) {
				fla=dfs(chen+1,num*arr[chen])?1:0;
			}else {
				fla=dfs(chen+1,num/arr[chen])?1:0;
			}
		}
		if (fla==1) {
			return true;
		}else {
			return false;
		}
		
	}
}